import * as types from "./actionTypes";
import store from "./index.js";
import axios from 'axios';

export const changeInputAction = (value) => {
	store.dispatch({
		type: types.CHANGE_INPUT,
		value,
	});
};

export const addItemAction = () => ({
	type: types.ADD_ITEM,
});

export const deleteItemAction = (index) => ({
	type: types.DELETE_ITEM,
	index,
});

export const getListAction = (data) => ({
	type: types.GET_LIST,
	data,
});

export const getTodoList = () => {
	// 返回一个函数
	return (dispatch) => {
		axios
			.get('http://rap2api.taobao.org/app/mock/238757/getList')
			.then((res) => {
				// console.log(res);
				const data = res.data;
				const action = getListAction(data);
				dispatch(action);
			});
	}
}

export const getMyListAction = () => ({
	type: types.GET_MY_LIST
})